package io.renren.modules.xk.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.Constant;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.xk.dao.XkTaskDao;
import io.renren.modules.xk.entity.XkTaskEntity;
import io.renren.modules.xk.service.XkTaskService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;


/**
 * 选课任务
 *
 * @author Mark sunlightcs@gmail.com
 */
@Service("xkTaskService")
public class XkTaskServiceImpl extends ServiceImpl<XkTaskDao, XkTaskEntity> implements XkTaskService {

	@Override
//	@DataFilter(subDept = true, user = false)
	public PageUtils queryPage(Map<String, Object> params) {
		String courseName = (String)params.get("courseName");

		IPage<XkTaskEntity> page = this.page(
			new Query<XkTaskEntity>().getPage(params),
			new QueryWrapper<XkTaskEntity>()
				.like(StringUtils.isNotBlank(courseName),"course_name", courseName)
				.apply(params.get(Constant.SQL_FILTER) != null, (String)params.get(Constant.SQL_FILTER))
		);
		return new PageUtils(page);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void saveEntity(XkTaskEntity taskEntity) {
		taskEntity.setStatus("0");
		this.save(taskEntity);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void update(XkTaskEntity taskEntity) {
		this.updateById(taskEntity);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public void taskRelease(XkTaskEntity taskEntity) {
		this.taskRelease(taskEntity);
	}

}
